---
title: Cache
sidebar:
  order: 15
description: Learn how LLM requests are cached in scripts to optimize
  performance and how to manage cache settings.
keywords: cache management, LLM request caching, script performance, cache file
  customization, cache disabling
hero:
  image:
    alt: A simple 8-bit icon displays a gray folder marked as ".genaiscript,"
      holding two rectangular file icons, one blue labeled "chat.jsonl" and one
      yellow labeled "summary.jsonl." The design uses flat, geometric shapes in
      gray, blue, yellow, black, and white, focusing solely on the folder and
      files to visually represent software caching, with no background or
      additional elements.
    file: ./cache.png

---

import { FileTree } from "@astrojs/starlight/components"

LLM requests are **NOT** cached by default. However, you can turn on LLM request caching from `script` metadata or the CLI arguments.

```js "cache: true"
script({
    ...,
    cache: true
})
```

or

```sh "--cache"
npx genaiscript run ... --cache
```

The cache is stored in the `.genaiscript/cache/chat.jsonl` file. You can delete this file to clear the cache.
This file is excluded from git by default.

<FileTree>

- .genaiscript
    - cache
        - chat.jsonl

</FileTree>

## Custom cache file

Use the `cacheName` option to specify a custom cache file name.
The name will be used to create a file in the `.genaiscript/cache` directory.

```js
script({
    ...,
    cache: "summary"
})
```

Or using the `--cache-name` flag in the CLI.

```sh
npx genaiscript run .... --cache-name summary
```

<FileTree>

- .genaiscript
    - cache
        - summary.jsonl

</FileTree>

## Programmatic cache

You can instantiate a custom cache object to manage the cache programmatically.

```js
const cache = await workspace.cache("custom")
// write entries
await cache.set("file.txt", "...")
// read value
const content = await cache.get("file.txt")
// list values
const values = await cache.values()
```
